import * as actionTypes from './constants'

import {
  getHotAlbums,
  getTopAlbums
} from '@/services/album'

export const changeHotAlbumsAction = (res) => ({
  type: actionTypes.CHANGE_HOT_ALBUMS,
  hotAlbums: res.albums,
})

export const changeTopAlbumsAction = res => ({
  type: actionTypes.CHANGE_TOP_ALBUMS,
  topAlbums: res.albums,
})

export const changeTopTotalAction = total => ({
  type: actionTypes.CHANGE_TOP_TOTAL,
  topTotal: total
})


export const getHotAlbumsAction = () => {
  return dispatch => {
    getHotAlbums().then(res => {
      dispatch(changeHotAlbumsAction(res));
    })
  }
}

export const getTopAlbumsAction = page => {
  return dispatch => {
    getTopAlbums(30, (page - 1) * 30).then(res => {
      dispatch(changeTopAlbumsAction(res));
      dispatch(changeTopTotalAction(res.total));
    })
  }
}